# Contributor: Grigory Kirillov <txgk@bk.ru>
# Maintainer: Grigory Kirillov <txgk@bk.ru>
pkgname=fheroes2
pkgver=0.9.17
pkgrel=0
pkgdesc="Recreation of HoMM2 game engine"
url="https://github.com/ihhub/fheroes2"
arch="all"
license="GPL-2.0-only"
options="!check" # no test suite
makedepends="
	gettext
	sdl2-dev
	sdl2_image-dev
	sdl2_mixer-dev
	zlib-dev
	"
subpackages="$pkgname-lang"
source="https://github.com/ihhub/fheroes2/archive/$pkgver/fheroes2-$pkgver.tar.gz"
install="$pkgname.post-install"
langdir="/usr/share/$pkgname/files/lang"

[ "$CARCH" = "riscv64" ] && options="$options textrels"

build() {
	make FHEROES2_WITH_IMAGE=1 FHEROES2_DATA=/usr/share/fheroes2

	# hu lt nl tr:
	#   these languages require iconv TRANSLIT extension to be built (musl doesn't support that)
	# ro:
	#   just fails to build because "ISO-8859-16" charset is not portable
	# fr:
	#   fails with "make: *** [Makefile:33: fr.mo] Error 254"
	for lang in hu lt nl tr ro fr; do
		rm files/lang/$lang.po
	done

	make -C files/lang
}

package() {
	install -Dm755 src/dist/fheroes2 -t "$pkgdir"/usr/bin/
	install -Dm644 script/packaging/common/fheroes2.desktop -t "$pkgdir"/usr/share/applications/
	install -Dm644 files/data/*.h2d -t "$pkgdir"/usr/share/"$pkgname"/files/data/
	install -Dm644 files/lang/*.mo -t "$pkgdir"/usr/share/"$pkgname"/files/lang/
	install -Dm755 script/demo/download_demo_version.sh -t "$pkgdir"/usr/share/"$pkgname"/
	install -Dm755 script/homm2/extract_homm2_resources.sh -t "$pkgdir"/usr/share/"$pkgname"/
	install -Dm644 src/resources/fheroes2.png -t "$pkgdir"/usr/share/pixmaps/
	install -dm755 "$pkgdir"/usr/share/fheroes2/data
	install -dm755 "$pkgdir"/usr/share/fheroes2/maps
}

sha512sums="
b12d84ada04c4f228f7e14a268a631eb43170b1a3259fbf95d02e5593b7e32ed6aad36c0e22bb0b7510d1f0fbcd9ffd810f1a329615609726dac2946a2e8ed82  fheroes2-0.9.17.tar.gz
"
